import requests
import os
import json


def main():
    url = 'http://127.0.0.1:18083/table/predict'
    current_dir = os.getcwd()
    result_file = os.path.join(current_dir, 'result1.txt')
    writes = {}
    for file in os.listdir('.\\test-100'):
        try:
            file_path = os.path.join('.\\test-100', file)
            files = { 'draft' : open(file_path, 'rb')}
            res = requests.post(url=url, files=files)
            writes[file] = res.json().get('data')
            print('%s 识别完成...' % file)
            with open(result_file, 'w', encoding='utf8') as fp:
                fp.write(json.dumps(writes, ensure_ascii=False))
        except Exception as e:
            print('接口异常：%s' % e)
            continue
    


if __name__ == '__main__':
    main()